;
; wvdWrite.asm
;
; wvdWrite(WINDOW * wptr,row,col,len,string,attr)
;
; WINDOW *wptr  pointer to window structure
; int row       row of string write
; int col       column of string write
; int len       number of bytes to write
; char *string  pointer to string to write
; int attr      attribute of screen write
;
;--------------------------------------
;
; include defs, prototypes and macros
;

include tab6.inc

;--------------------------------------
;
; begin code segment
;

	.CODE

wvdWrite PROC PASCAL PUBLIC USES es ds di ds si bx,wptr:Ptr Window,row:BYTE,col:BYTE,lgth:WORD,str1:PBYTE,attr:BYTE
        LOCAL   ur:Byte,uc:Byte
;
; relocate Window structure data to locals
   IF mdl eq 1
        mov     bx,wptr
   ELSE
        lds     bx,wptr
   ENDIF

        mov     al,(WINDOW Ptr [bx]).ur ; relocate upper row
        mov     ur,al
        mov     al,(WINDOW Ptr [bx]).uc ; relocate upper col
        mov     uc,al

; ds:si points to source string

 IF mdl eq 3
        lds     si,str1
  ELSE
        mov     si,str1
  ENDIF

; es gets screen segment

 IF mdl eq 3
	push	ds
	mov	ax,SEG scrn_seg
	mov	ds,ax
	mov	ax,ds:scrn_seg
	mov	es,ax
	pop	ds
 ELSE
	mov	ax,scrn_seg
	mov	es,ax
 ENDIF
	sub	ax,ax         ; 0 -> ax
	mov	al,row        ; row -> al
        add     al,ur         ; adjust for window global coord.
	mov	bl,160        ; 160 = (80 chars wide * 2)
	mul	bl            ; row * scrn width  -> ax
	mov	cl,col        ; column to cl
        add     cl,uc         ; adjust for window global coord.
	sub	ch,ch         ; 0 -> ch
	shl	cx,1          ; col * 2
	add	ax,cx         ; column + (row * scrn width)
	mov	di,ax         ; point di to scrn
	cld                   ; direction increment
	mov	ah,attr       ; make word token
	mov	cx,lgth       ; string length -> cx
	.IF (cx>0)
	jmp vdr1
	.ENDIF
	.WHILE 1
        lodsb   
	.IF (al==0)
	ret
	.ENDIF
        stosw
	.ENDW
vdr1:
	.REPEAT
	lodsb	              ; get byte from string
	stosw	              ; token to screen
	dec	cx
	.UNTIL (cx==0)
	ret
wvdWrite	ENDP
	END
	
	

